let my_char_of_int = function
  | 0 -> '0'
  | 1 -> '1'
  | 2 -> '2'
  | 3 -> '3'
  | 4 -> '4'
  | 5 -> '5'
  | 6 -> '6'
  | 7 -> '7'
  | 8 -> '8'
  | 9 -> '9'
  | c -> char_of_int c

let my_int_of_char = function
  | '0' -> 0
  | '1' -> 1
  | '2' -> 2
  | '3' -> 3
  | '4' -> 4
  | '5' -> 5
  | '6' -> 6
  | '7' -> 7
  | '8' -> 8
  | '9' -> 9
  | c -> int_of_char c

let my_string_of_int = function
  | i when i < 10 -> "00" ^ string_of_int i
  | i when i < 100 -> "0" ^ string_of_int i
  | i -> string_of_int i

(* renvoit une chaine "REDGREBLU" a partir du triplet d'entiers
   (RED,GRE,BLU) *)
let string_of_color (r,g,b) =
  my_string_of_int r ^
    my_string_of_int g ^
    my_string_of_int b

(* renvoit un triplet de float à partir d'une ligne du fichier OBJ *)
let int_triple_of_string s =
  let i = ref 2 in
  let n = ref 1 in
  let x = ref 0 in
  let y = ref 0 in
  let z = ref 0 in
  begin
    while (s.[!i] <> ' ') do
      x := !x + (my_int_of_char s.[!i]) * !n;
      n := !n * 10;
      i := !i + 1;
    done;
    n := 1;
    i := !i + 1;
    while (s.[!i] <> ' ') do
      y := !y + (my_int_of_char s.[!i]) * !n;
      n := !n * 10;
      i := !i + 1;
    done;
    n := 1;
    i := !i + 1;
    while (!i < (String.length s - 1)) do
      z := !z + (my_int_of_char s.[!i]) * !n;
      n := !n * 10;
      i := !i + 1;
    done;
    (!x, !y, !z)
  end

let vertex_of_string s =
  let (x,y,z) = int_triple_of_string s in
  (float_of_int x, float_of_int y, float_of_int z)
